#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
struct student
{
    char name[9];
    int a;
    int b;
    int c;

};
int main()
{
    int n;
    scanf("%d", &n);
    struct student s[1001];
    for (int i = 0;i < n;i++)
    {
        scanf("%s", s[i].name);
        scanf("%d %d %d", &s[i].a, &s[i].b, &s[i].c);

    }
    int year, month, day;
    scanf("%d %d %d", &year, &month, &day);
    int n1 = s[0].a;
    int n2 = s[0].b;
    int n3 = s[0].c;
    int xb = 0;
    for (int i = 0;i < n;i++)
    {
        if (s[i].a > n1)
        {
            n1 = s[i].a;
            xb = i;
        }
        else if (s[i].a == n1)
        {
            if (s[i].b > n2)
            {
                n2 = s[i].b;
                xb = i;
            }
            else if (s[i].b == n2)

            {
                if (s[i].c > n3)
                {
                    n3 = s[i].c;
                    xb = i;
                }
            }
        }
    }
    printf("%s %d-%02d-%02d", s[xb].name, s[xb].a, s[xb].b, s[xb].c);

    return 0;
}